package demo.projecttask.model;

import demo.common.dao.BaseProvider;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Created by llq on 2017/12/11.
 */
@BaseProvider.Table(tableName = "t_task")
public class Task {
    public static final Integer ROOT = -1;

    private Integer id;
    private Integer parentid = ROOT;

    @Update
    private String name = "";

    @UpdateChildCount
    private Integer childCount = 0;

    /**
     * 备注
     */
    @Update
    private String remark;

    @UpdateDeleteStatus
    private Boolean deleted = false;

    public Integer getChildCount() {
        return childCount;
    }

    public void setChildCount(Integer childCount) {
        this.childCount = childCount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getParentid() {
        return parentid;
    }

    public void setParentid(Integer parentid) {
        if (parentid == null) {
            parentid = ROOT;
        }
        this.parentid = parentid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void delete() {
        this.deleted = true;
    }

    public boolean topTask() {
        return ROOT.equals(parentid);
    }

    public void addChildCount(int count) {
        this.childCount += count;
    }

    public void subChildCount(int count) {
        this.childCount -= count;
    }

    @Retention(RetentionPolicy.RUNTIME)
    public static @interface UpdateDeleteStatus {
    }

    @Retention(RetentionPolicy.RUNTIME)
    public static @interface Update {
    }

    @Retention(RetentionPolicy.RUNTIME)
    public static @interface UpdatePercent {
    }

    @Retention(RetentionPolicy.RUNTIME)
    public static @interface UpdateChildCount {
    }

    public static enum Status {
        /**
         * 未开始
         */
        INIT,

        /**
         * 已经结束
         */
        FINISHED,

        /**
         * 进行中
         */
        PROCESSING
    }

}
